package demo05092;

import java.util.ArrayList;
import java.util.List;

public class ListDemo {// 设置学校和学生的关系
	public static int count(List<Student> studentList) {
		int n = 0;
		for (Student s : studentList) {
			if (s.getAge() == 22) {
				n++;
			}
		}
		return n;
	}
	public static void main(String args[]) {

		Student s1 = new Student("张三", 21);// 实例化学生对象
		Student s2 = new Student("李四", 22);
		Student s3 = new Student("王五", 23);
		List<Student> studentList = new ArrayList<>();
		studentList.add(s1);
		studentList.add(s2);
		studentList.add(s3);
          int n   =ListDemo.count(studentList);
          
	}
}

// 学生类
class Student {
	private String name;
	private int age;

	public Student(String name, int age) {
		this.setName(name);
		this.setAge(age);
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return this.name;
	}

	public int getAge() {
		return this.age;
	}

	public String toString() {
		return "学生姓名：" + this.name + "；年龄：" + this.age;
	}
}